import requests
import json
import os
import re
from urllib import parse
from threading import Thread

path = '王者荣耀高清壁纸1920-1400'
if not os.path.exists(path):
    os.mkdir(path)
headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36'
    }
def do_it(i):
    name = i['sProdName']
    name = parse.unquote(name)
    img_url = i['sProdImgNo_8']
    img_url = parse.unquote(img_url)
    img_url = re.findall('(.*)/',img_url)[0]
    img_url = img_url+'/0'
    html = requests.get(img_url,headers=headers)
    img_add = path+'/'+name+'.jpg'
    with open (img_add,'wb') as f:
        f.write(html.content)
    print(name,'  保存成功！')
for page in range(23):
    url = 'https://apps.game.qq.com/cgi-bin/ams/module/ishow/V1.0/query/workList_inc.cgi?activityId=2735&sVerifyCode=ABCD&sDataType=JSON&iListNum=20&totalpage=0&page=%s&iOrder=0&iSortNumClose=1&jsoncallback=jQuery171011945906312821042_1584941478317&iAMSActivityId=51991&_everyRead=true&iTypeId=2&iFlowId=267733&iActId=2735&iModuleId=2735&_=1584941496555'%page
    html = requests.get(url,headers=headers)
    text = html.text
    data = re.findall('.*?\((.*)\)',text,re.S)[0]
    data = json.loads(data)
    #print(data)
    data = data['List']
    listt = []
    for i in data:
        t = Thread(target=do_it,args=(i,))
        t.start()
        listt.append(t)
    for t in listt:
        t.join()